package com.roc.admin.infrastructure.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;

import javax.sql.DataSource;

/**
 * 测试环境配置类
 */
@Configuration
@Profile("test")
public class TestConfig {

    /**
     * 配置内存数据库用于测试
     *
     * @return 数据源
     */
    @Bean
    public DataSource dataSource() {
        return new EmbeddedDatabaseBuilder()
                .setType(EmbeddedDatabaseType.H2)
                .addScript("classpath:db/schema-h2.sql")
                .addScript("classpath:db/data-h2.sql")
                .build();
    }
}
